home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1800 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.2 KB

  1. Path: colossus.holonet.net!russell
  2. From: russell@news.mdli.com (Russell Blackadar)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Question: references to variables within classes
  5. Date: 12 Jan 1996 23:23:40 GMT
  6. Organization: HoloNet National Internet Access System: 510-704-1058/modem
  7. Message-ID: <4d6qhs$ie@colossus.holonet.net>
  8. References: <DKy0MC.3nA@watserv3.uwaterloo.ca>
  9. NNTP-Posting-Host: jubal.mdli.com
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Stephen Bay (sdbay@watnow.uwaterloo.ca) wrote:
  13. : Hi,
  14.  
  15. : Is it possible in C++ to use variables within a class as 
  16. parameters for a 
  17. : constructor of an object contained within that class? I've
  18. tried compiling the 
  19.  
  20. (deleted stuff)
  21.  
  22. : class    dodo
  23. : {
  24. :           public:
  25. :               NISList<int *>       CityList;
  26. : chokes here->    NISListIter<int *>   CityListIter(CityList);
  27. : };                                             ^^^^^^^^^^
  28.  
  29. The underlined stuff is an initializer.  This is not legal
  30. inside a class definition.  Instead, you need to do the
  31. initialization in dodo's constructor, e.g.
  32.  
  33.   dodo::dodo() : CityList(), CityListIter(CityList) {}
  34.  
  35. So, the answer to your question is yes, if you do it legally.
  36. --
  37. Russell Blackadar,   russell@mdli.com
  38.